package com.xuhai.book.controller;

import com.xuhai.book.bean.Publisher;
import com.xuhai.book.service.PublisherService;
import com.xuhai.book.util.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/publisher")
public class PublisherController {

    @Autowired
    private PublisherService publisherService;

    @GetMapping("/page")
    public ResultJson page(int page, int limit, Publisher publisher){
        return publisherService.getPage(page, limit, publisher);
    }

    @GetMapping("/info/{publisherId}")
    public ResultJson info(@PathVariable Integer publisherId){
        return publisherService.getById(publisherId);
    }

    @PostMapping(value = {"/update","/status","/order/num"})
    public ResultJson update(@RequestBody Publisher publisher){
        publisherService.saveOrUpdate(publisher);
        return ResultJson.ok();
    }

    @DeleteMapping("/delete/{publisherId}")
    public ResultJson delete(Integer publisherId){
        publisherService.deleteById(publisherId);
        return ResultJson.ok();
    }
}
